Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use ctx.Locale.Tr inside templates #27231

Merged
merged 11 commits into from
Sep 25, 2023

Conversation

delvh
Copy link
Member

@delvh delvh commented Sep 24, 2023

Refactoring performed using

cd templates/
ag --only-matching --nofilename '[^{()\s]+\.Tr\b' | sed 's/ //g' | uniq --unique | sort -h | uniq --unique

 # Then pipe into vim, execute ':sort u', throw out `ctx.Locale.Tr`, and save as '../bad-instances'

for bad_instance in $(cat ../bad-instances); do
  echo $bad_instance;
  for file in $(ag --literal --files-with-matches "$bad_instance") ; do
    vim "$file" -c ":%s/\(\<\)\?$bad_instance\(\>\)\?/\1ctx.Locale.Tr\2" -c ':wq' ;
  done;
done

# Edge cases that are not covered by above
for file in $(ag --files-with-matches -Q '$ctx.Locale.Tr') ; do vim $file -c ':%s/\$ctx\.Locale\.Tr/ctx\.Locale\.Tr/g' -c ':wq'; done
git checkout da0467e3b -- ./status/500.tmpl
for file in $(ag --files-with-matches -Q '$.rootctx.Locale.Tr') ; do vim $file -c ':%sno/$.rootctx.Locale.Tr/ctx.Locale.Tr/g' -c ':wq'; done
for file in $(ag --files-with-matches -Q  '.rootctx.Locale.Tr') ; do vim $file -c ':%sno/.rootctx.Locale.Tr/ctx.Locale.Tr/g' -c ':wq'; done
for file in $(ag --files-with-matches -Q  '.ctxDatactx.Locale.Tr') ; do vim $file -c ':%sno/.ctxDatactx.Locale.Tr/ctx.Locale.Tr/g' -c ':wq'; done

This PR is a corollary to #27227 as that PR removes the unneeded locale parameters from subtemplates.

@delvh delvh added topic/ui Change the appearance of the Gitea UI type/refactoring Existing code has been cleaned up. There should be no new functionality. labels Sep 24, 2023
@delvh delvh requested a review from denyskon September 24, 2023 15:46
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 24, 2023
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 24, 2023
@wxiaoguang
Copy link
Contributor

500.tmpl is special, it can't use ctx at the moment.

@delvh
Copy link
Member Author

delvh commented Sep 24, 2023

Done

Refactoring performed using
```bash
cd templates/
ag --only-matching --nofilename '[^{()\s]+\.Tr\b' | sed 's/ //g' | uniq --unique | sort -h | uniq --unique

 # Then pipe into vim, execute ':sort u', throw out `ctx.Locale.Tr`, and save as '../bad-instances'

for bad_instance in $(cat ../bad-instances); do
  echo $bad_instance;
  for file in $(ag --literal --files-with-matches "$bad_instance") ; do
    vim "$file" -c ":%s/\(\<\)\?$bad_instance\(\>\)\?/\1ctx.Locale.Tr\2" -c ':wq' ;
  done;
done

 # Edge cases that are not covered by above
for file in $(ag --files-with-matches -Q '$ctx.Locale.Tr') ; do vim $file -c ':%s/\$ctx\.Locale\.Tr/ctx\.Locale\.Tr/g' -c ':wq'; done
git checkout da0467e -- ./status/500.tmpl
for file in $(ag --files-with-matches -Q '$.rootctx.Locale.Tr') ; do vim $file -c ':%sno/$.rootctx.Locale.Tr/ctx.Locale.Tr/g' -c ':wq'; done
for file in $(ag --files-with-matches -Q  '.rootctx.Locale.Tr') ; do vim $file -c ':%sno/.rootctx.Locale.Tr/ctx.Locale.Tr/g' -c ':wq'; done
for file in $(ag --files-with-matches -Q  '.ctxDatactx.Locale.Tr') ; do vim $file -c ':%sno/.ctxDatactx.Locale.Tr/ctx.Locale.Tr/g' -c ':wq'; done
```
Copy link
Member

@denyskon denyskon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't go through all files, but it looks good to me in general. I think we should merge, and fix possible issues when they appear. Thanks @delvh

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Sep 24, 2023
@delvh
Copy link
Member Author

delvh commented Sep 24, 2023

Hmm… Is the current CI failure related to my changes or not?
I'm rather leaning towards unrelated.

@denyskon denyskon self-requested a review September 24, 2023 17:29
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 24, 2023
@denyskon
Copy link
Member

Looks related to me.... the few tests I looked at refer to some text inside pages, or http errors... looks like broken templates

@delvh
Copy link
Member Author

delvh commented Sep 24, 2023

Found the culprit.
Am currently fixing it.

@delvh
Copy link
Member Author

delvh commented Sep 24, 2023

Okay, now I am confused:
According to the CI, my changes appear to be responsible for the failure.
However, I cannot reproduce the 500 locally.
I cannot even find a template that is called by the respective method.
So, I have no idea what is going wrong here.
Does anyone else have an idea?

@denyskon
Copy link
Member

@delvh It's the mail template under templates/mail/team_invite.tmpl.
It doesn't seem to work with ctx.Locale.Tr. When changing back to .locale.Tr, the tests pass

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Sep 24, 2023
Copy link
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm after ci passes

@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Sep 25, 2023
@delvh delvh added the backport/v1.21 This PR should be backported to Gitea 1.21 label Sep 25, 2023
@delvh delvh added reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. reviewed/prioritize-merge PR is in the merge queue. Merge as soon as possible, i.e. as edits by maintainers are not enabled labels Sep 25, 2023
@techknowlogick techknowlogick merged commit 7960ba7 into go-gitea:main Sep 25, 2023
25 checks passed
@GiteaBot GiteaBot added this to the 1.22.0 milestone Sep 25, 2023
@GiteaBot
Copy link
Contributor

I was unable to create a backport for 1.21. @delvh, please send one manually. 🍵

go run ./contrib/backport 27231
...  // fix git conflicts if any
go run ./contrib/backport --continue

@GiteaBot GiteaBot added backport/manual No power to the bots! Create your backport yourself! and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. reviewed/prioritize-merge PR is in the merge queue. Merge as soon as possible, i.e. as edits by maintainers are not enabled labels Sep 25, 2023
wxiaoguang pushed a commit to wxiaoguang/gitea that referenced this pull request Sep 25, 2023
@wxiaoguang
Copy link
Contributor

-> Backport ctx locale refactoring manually #27260

wxiaoguang added a commit that referenced this pull request Sep 25, 2023
Backport #27231 #27259 manually

---------

Co-authored-by: delvh <dev.lh@web.de>
@delvh delvh deleted the ctx-locale-tr-everywhere branch September 25, 2023 14:56
zjjhot added a commit to zjjhot/gitea that referenced this pull request Sep 26, 2023
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Another round of `db.DefaultContext` refactor (go-gitea#27103)
  Fix more "locale" usages (go-gitea#27259)
  Always use `ctx.Locale.Tr` inside templates (go-gitea#27231)
  Disable `Test Delivery` and `Replay` webhook buttons when webhook is inactive (go-gitea#27211)

# Conflicts:
#	templates/base/footer_content.tmpl
#	templates/repo/issue/view_content/context_menu.tmpl
delvh added a commit to delvh/gitea that referenced this pull request Sep 26, 2023
wxiaoguang pushed a commit that referenced this pull request Sep 26, 2023
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Sep 26, 2023
lunny pushed a commit that referenced this pull request Sep 26, 2023
Backport #27275 by @delvh

Co-authored-by: delvh <dev.lh@web.de>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Sep 28, 2023
* giteaoffical/main: (22 commits)
  Fix review UI (go-gitea#27322)
  Improve issue history dialog and make poster can delete their own history (go-gitea#27323)
  Improve branch list UI (go-gitea#27319)
  doctor: delete action entries without existing user (go-gitea#27292)
  fix orphan check for deleted branch (go-gitea#27310)
  make writing main test easier (go-gitea#27270)
  [skip ci] Updated translations via Crowdin
  Fix protected branch icon location (go-gitea#26576)
  move the `gitea admin` subcommands into separate files (go-gitea#27307)
  Fix chinese translation (go-gitea#27296)
  bump bleve (go-gitea#27300)
  Redefine the meaning of column is_active to make Actions Registration Token generation easier (go-gitea#27143)
  Use vitest globals (go-gitea#27102)
  Fix divider in subscription page (go-gitea#27298)
  Fix yaml test (go-gitea#27297)
  Enable production source maps for index.js, fix CSS sourcemaps (go-gitea#27291)
  Fix some animation bugs (go-gitea#27287)
  Add missed return to actions view fetch (go-gitea#27289)
  Fix more yaml lint errors (go-gitea#27284)
  Fix incorrect change from go-gitea#27231 (go-gitea#27275)
  ...
kerwin612 added a commit to kerwin612/gitea that referenced this pull request Nov 3, 2023
@lng2020 lng2020 added backport/done All backports for this PR have been created and removed backport/manual No power to the bots! Create your backport yourself! labels Nov 12, 2023
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. topic/ui Change the appearance of the Gitea UI type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants